﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace DataLibrary
{
   public class Ctbl_Auto:IData<tbl_Auto>
    {
       public Ctbl_Auto(String myconnecString) : base(myconnecString) { }

       protected override int InsertOnSubmit(tbl_Auto item, int t)
       {
           return connec.ExecuteNonQuery("CRUDNews", CommandType.StoredProcedure, new SqlParameter("@flag", t),
               new SqlParameter("@" + tbl_Auto.c_Content, item.Content), new SqlParameter("@" + tbl_Auto.c_Description, item.Description),
               new SqlParameter("@"+tbl_Auto.c_Id,item.Id),new SqlParameter("@"+tbl_Auto.c_Pubdate,item.Pubdate),
               new SqlParameter("@"+tbl_Auto.c_Title,item.Title),new SqlParameter("@"+tbl_Auto.c_url,item.Url),
               new SqlParameter("@"+tbl_Auto.c_WebsiteId,item.WebsiteId));
       }

       public override List<tbl_Auto> GetAll(tbl_Auto item)
       {
           throw new NotImplementedException();
       }

       public override tbl_Auto GetItemById(object id){
           return GetAll().SingleOrDefault(p => p.Id == Convert.ToInt32(id));
       }

       public override tbl_Auto GetItem(IDataReader dr)
       {
           tbl_Auto obj = new tbl_Auto();
           obj.Content = Convert.ToString(dr[tbl_Auto.c_Content]);
           obj.Description = Convert.ToString(dr[tbl_Auto.c_Description]);
           obj.Id = Convert.ToInt32(dr[tbl_Auto.c_Id]);
           obj.Pubdate = Convert.ToDateTime(dr[tbl_Auto.c_Pubdate]);
           obj.Title = Convert.ToString(dr[tbl_Auto.c_Title]);
           obj.Url = Convert.ToString(dr[tbl_Auto.c_url]);
           obj.WebsiteId = Convert.ToInt32(dr[tbl_Auto.c_WebsiteId]);
           return obj;
       }

       public List<tbl_Auto>GetListNews(int id){
           String strSql="select * from  " + tbl_Auto.b_tbl_News +" where "+ tbl_Auto.c_WebsiteId + "=@" + tbl_Auto.c_WebsiteId;
           return GetListParameter(strSql,CommandType.Text,new SqlParameter("@" + tbl_Auto.c_WebsiteId,id));
       }

       public override List<tbl_Auto> GetAll()
       {
           return GetAll("select * from " + tbl_Auto.b_tbl_News, CommandType.Text);
       }

    }
}
